<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./js/vue.js"></script>
</head>

<body>
    <div id="app">
        <ul>
            <li v-for="item in list">
                <span @click="change(item)">{{item.name}}</span>
                <ul v-show="activeIndex == item.id">
                    <li v-for="info  in  item.list">
                        {{info.name}}
                    </li>
                </ul>
            </li>
        </ul>
    </div>


</body>
<script>
    new Vue({
        el: "#app",
        data: {
            activeIndex: 0,
            list: [{ id: 1, name: "菜单1", list: [{ id: 11, name: "菜单1.1" }, { id: 12, name: "菜单1.2" }] },
            { id: 2, name: "菜单2", list: [{ id: 21, name: "菜单2.1" }, { id: 22, name: "菜单2.2" }] },
            { id: 3, name: "菜单3", list: [{ id: 31, name: "菜单3.1" }, { id: 32, name: "菜单3.2" }] }
            ]
        },
        methods: {
            change(item) {
                this.activeIndex = item.id == this.activeIndex ? 0 : item.id;
            }
        }
    })

</script>

</html>